home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / dflat8.zip / MEMOPAD.C < prev    next >
Text File  |  1991-09-30  |  18KB  |  610 lines

  1. /* --------------- memopad.c ----------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. extern DBOX PrintSetup;
  6.  
  7. char DFlatApplication[] = "MemoPad";
  8.  
  9. static char Untitled[] = "Untitled";
  10. static int wndpos;
  11.  
  12. static int MemoPadProc(WINDOW, MESSAGE, PARAM, PARAM);
  13. static void NewFile(WINDOW);
  14. static void SelectFile(WINDOW);
  15. static void PadWindow(WINDOW, char *);
  16. static void OpenPadWindow(WINDOW, char *);
  17. static void LoadFile(WINDOW);
  18. static void PrintPad(WINDOW);
  19. static void SaveFile(WINDOW, int);
  20. static void DeleteFile(WINDOW);
  21. static int EditorProc(WINDOW, MESSAGE, PARAM, PARAM);
  22. static char *NameComponent(char *);
  23. static int PrintSetupProc(WINDOW, MESSAGE, PARAM, PARAM);
  24. static void FixTabMenu(void);
  25. #ifndef TURBOC
  26. void Calendar(WINDOW);
  27. #endif
  28. void BarChart(WINDOW);
  29. char **Argv;
  30.  
  31. static int CancelPrint;
  32. #define CHARSLINE 80
  33. #define LINESPAGE 66
  34.  
  35. #ifdef BCPP
  36. /* --- to bypass Borland C++ precompiled header problem --- */
  37. extern int far cdecl _setargv__;
  38. static void far *bozo = &_setargv__;
  39. #endif
  40.  
  41. void main(int argc, char *argv[])
  42. {
  43.     WINDOW wnd;
  44.     init_messages();
  45.     Argv = argv;
  46.     wnd = CreateWindow(APPLICATION,
  47.                         "D-Flat MemoPad " VERSION,
  48.                         0, 0, -1, -1,
  49.                         &MainMenu,
  50.                         NULL,
  51.                         MemoPadProc,
  52.                         MOVEABLE  |
  53.                         SIZEABLE  |
  54.                         HASBORDER |
  55.                         HASSTATUSBAR
  56.                         );
  57.  
  58.     SendMessage(wnd, SETFOCUS, TRUE, 0);
  59.     while (argc > 1)    {
  60.         PadWindow(wnd, argv[1]);
  61.         --argc;
  62.         argv++;
  63.     }
  64.     while (dispatch_message())
  65.         ;
  66. }
  67. /* ------ open text files and put them into editboxes ----- */
  68. static void PadWindow(WINDOW wnd, char *FileName)
  69. {
  70.     int ax, criterr = 1;
  71.     struct ffblk ff;
  72.     char path[64];
  73.     char *cp;
  74.  
  75.     CreatePath(path, FileName, FALSE, FALSE);
  76.     cp = path+strlen(path);
  77.     CreatePath(path, FileName, TRUE, FALSE);
  78.     while (criterr == 1)    {
  79.         ax = findfirst(path, &ff, 0);
  80.         criterr = TestCriticalError();
  81.     }
  82.     while (ax == 0 && !criterr)    {
  83.         strcpy(cp, ff.ff_name);
  84.         OpenPadWindow(wnd, path);
  85.         ax = findnext(&ff);
  86.     }
  87. }
  88. /* ------- window processing module for the
  89.                     memopad application window ----- */
  90. static int MemoPadProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  91. {
  92.     int rtn;
  93.     switch (msg)    {
  94.         case CREATE_WINDOW:
  95.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  96.             if (cfg.InsertMode)
  97.                 SetCommandToggle(&MainMenu, ID_INSERT);
  98.             if (cfg.WordWrap)
  99.                 SetCommandToggle(&MainMenu, ID_WRAP);
  100.             FixTabMenu();
  101.             return rtn;
  102.         case COMMAND:
  103.             switch ((int)p1)    {
  104.                 case ID_NEW:
  105.                     NewFile(wnd);
  106.                     return TRUE;
  107.                 case ID_OPEN:
  108.                     SelectFile(wnd);
  109.                     return TRUE;
  110.                 case ID_SAVE:
  111.                     SaveFile(inFocus, FALSE);
  112.                     return TRUE;
  113.                 case ID_SAVEAS:
  114.                     SaveFile(inFocus, TRUE);
  115.                     return TRUE;
  116.                 case ID_DELETEFILE:
  117.                     DeleteFile(inFocus);
  118.                     return TRUE;
  119.                 case ID_PRINTSETUP:
  120.                     DialogBox(wnd, &PrintSetup, TRUE, PrintSetupProc);
  121.                     return TRUE;
  122.                 case ID_PRINT:
  123.                     PrintPad(inFocus);
  124.                     return TRUE;
  125.                 case ID_TAB2:
  126.                     cfg.Tabs = 2;
  127.                     FixTabMenu();
  128.                     return TRUE;
  129.                 case ID_TAB4:
  130.                     cfg.Tabs = 4;
  131.                     FixTabMenu();
  132.                     return TRUE;
  133.                 case ID_TAB6:
  134.                     cfg.Tabs = 6;                    
  135.                     FixTabMenu();
  136.                     return TRUE;
  137.                 case ID_TAB8:
  138.                     cfg.Tabs = 8;
  139.                     FixTabMenu();
  140.                     return TRUE;
  141.                 case ID_CANCEL:
  142.                     if ((int)p2 == 0)
  143.                         CancelPrint = TRUE;
  144.                     return TRUE;
  145.                 case ID_CALENDAR:
  146. #ifndef TURBOC
  147.                     Calendar(wnd);
  148. #endif
  149.                     return TRUE;
  150.                 case ID_BARCHART:
  151.                     BarChart(wnd);
  152.                     return TRUE;
  153.                 case ID_ABOUT:
  154.                     MessageBox(
  155.                          "About D-Flat and the MemoPad",
  156.                         "   ┌───────────────────────┐\n"
  157.                         "   │    ▄▄▄   ▄▄▄     ▄    │\n"
  158.                         "   │    █  █  █  █    █    │\n"
  159.                         "   │    █  █  █  █    █    │\n"
  160.                         "   │    █  █  █  █ █  █    │\n"
  161.                         "   │    ▀▀▀   ▀▀▀   ▀▀     │\n"
  162.                         "   └───────────────────────┘\n"
  163.                         "D-Flat implements the SAA/CUA\n"
  164.                         "interface in a public domain\n"
  165.                         "C language library originally\n"
  166.                         "published in Dr. Dobb's Journal\n"
  167.                         "    ------------------------ \n"
  168.                         "MemoPad is a multiple document\n"
  169.                         "editor that demonstrates D-Flat");
  170.                     return TRUE;
  171.                 default:
  172.                     break;
  173.             }
  174.             break;
  175.         default:
  176.             break;
  177.     }
  178.     return DefaultWndProc(wnd, msg, p1, p2);
  179. }
  180. /* --- The New command. Open an empty editor window --- */
  181. static void NewFile(WINDOW wnd)
  182. {
  183.     OpenPadWindow(wnd, Untitled);
  184. }
  185. /* --- The Open... command. Select a file  --- */
  186. static void SelectFile(WINDOW wnd)
  187. {
  188.     char FileName[64];
  189.     if (OpenFileDialogBox("*.PAD", FileName))    {
  190.         /* --- see if the document is already in a window --- */
  191.         WINDOW wnd1 = GetFirstChild(wnd);
  192.         while (wnd1 != NULL)    {
  193.             if (stricmp(FileName, wnd1->extension) == 0)    {
  194.                 SendMessage(wnd1, SETFOCUS, TRUE, 0);
  195.                 SendMessage(wnd1, RESTORE, 0, 0);
  196.                 return;
  197.             }
  198.             wnd1 = GetNextChild(wnd, wnd1);
  199.         }
  200.         OpenPadWindow(wnd, FileName);
  201.     }
  202. }
  203.  
  204. /* --- open a document window and load a file --- */
  205. static void OpenPadWindow(WINDOW wnd, char *FileName)
  206. {
  207.     static WINDOW wnd1 = NULL;
  208.     struct stat sb;
  209.     char *Fname = FileName;
  210.     char *ermsg;
  211.     if (strcmp(FileName, Untitled))    {
  212.         if (stat(FileName, &sb))    {
  213.             if ((ermsg = malloc(strlen(FileName)+20)) != NULL) {
  214.                 strcpy(ermsg, "No such file as\n");
  215.                 strcat(ermsg, FileName);
  216.                 ErrorMessage(ermsg);
  217.                 free(ermsg);
  218.             }
  219.             return;
  220.         }
  221.         Fname = NameComponent(FileName);
  222.     }
  223.     wndpos += 2;
  224.     if (wndpos == 20)
  225.         wndpos = 2;
  226.     wnd1 = CreateWindow(EDITBOX,
  227.                 Fname,
  228.                 (wndpos-1)*2, wndpos, 10, 40,
  229.                 NULL, wnd, EditorProc,
  230.                 SHADOW     |
  231.                 MINMAXBOX  |
  232.                 CONTROLBOX |
  233.                 VSCROLLBAR |
  234.                 HSCROLLBAR |
  235.                 MOVEABLE   |
  236.                 HASBORDER  |
  237.                 SIZEABLE   |
  238.                 MULTILINE
  239.     );
  240.     if (strcmp(FileName, Untitled))    {
  241.         if ((wnd1->extension = malloc(strlen(FileName)+1)) != NULL)    {
  242.             strcpy(wnd1->extension, FileName);
  243.             LoadFile(wnd1);
  244.         }
  245.     }
  246.     SendMessage(wnd1, SETFOCUS, TRUE, 0);
  247. }
  248. /* --- Load the notepad file into the editor text buffer --- */
  249. static void LoadFile(WINDOW wnd)
  250. {
  251.     char *Buf = NULL;
  252.     int recptr = 0;
  253.     FILE *fp;
  254.  
  255.     if ((fp = fopen(wnd->extension, "rt")) != NULL)    {
  256.         while (!feof(fp))    {
  257.             if ((Buf = realloc(Buf, recptr+150)) == NULL)
  258.                 break;
  259.             fgets(Buf+recptr, 150, fp);
  260.             recptr += strlen(Buf+recptr);
  261.         }
  262.         fclose(fp);
  263.         if (Buf != NULL)    {
  264.             SendMessage(wnd, SETTEXT, (PARAM) Buf, 0);
  265.             free(Buf);
  266.         }
  267.     }
  268. }
  269. /* --- print the current notepad --- */
  270. static void PrintPad(WINDOW wnd)
  271. {
  272.     unsigned char *text;
  273.     FILE *prn;
  274.     int LineCtr = 0, CharCtr = 0;
  275.  
  276.     if (*cfg.PrinterPort)    {
  277.         if ((prn = fopen(cfg.PrinterPort, "wt")) != NULL)    {
  278.             /* ---- get the address of the editor text ----- */
  279.             text = GetText(wnd);
  280.             CancelPrint = FALSE;
  281.             CancelBox(GetParent(wnd), "Printing...");
  282.             /* ------- print the notepad text --------- */
  283.             while (*text)    {
  284.                 int i;
  285.                 dispatch_message();
  286.                 if (CancelPrint)
  287.                     if (YesNoBox("Cancel Printing?"))
  288.                         break;
  289.                 CancelPrint = FALSE;
  290.                 if (*text == '\n' || CharCtr == cfg.RightMargin)    {
  291.                     fputs("\r\n", prn);
  292.                     LineCtr++;
  293.                     if (LineCtr == cfg.BottomMargin)    {
  294.                         fputc('\f', prn);
  295.                         for (i = 0; i < cfg.TopMargin; i++)
  296.                             fputc('\n', prn);
  297.                         LineCtr = cfg.TopMargin;
  298.                     }
  299.                     CharCtr = 0;
  300.                     if (*text == '\n')    {
  301.                         text++;
  302.                         continue;
  303.                     }
  304.                 }
  305.                 if (CharCtr == 0)    {
  306.                     for (i = 0; i < cfg.LeftMargin; i++)    {
  307.                         fputc(' ', prn);
  308.                         CharCtr++;
  309.                     }
  310.                 }
  311.                 CharCtr++;
  312.                 fputc(*text++, prn);
  313.             }
  314.             CloseCancelBox();
  315.  
  316.             /* ------- follow with a form feed? --------- */
  317.             if (YesNoBox("Form Feed?"))
  318.                 fputc('\f', prn);
  319.             fclose(prn);
  320.         }
  321.         else
  322.             ErrorMessage("Cannot open printer file");
  323.     }
  324.     else
  325.         ErrorMessage("No printer selected");
  326. }
  327. /* ---------- save a file to disk ------------ */
  328. static void SaveFile(WINDOW wnd, int Saveas)
  329. {
  330.     FILE *fp;
  331.     if (wnd->extension == NULL || Saveas)    {
  332.         char FileName[64];
  333.         if (SaveAsDialogBox(FileName))    {
  334.             if (wnd->extension != NULL)
  335.                 free(wnd->extension);
  336.             if ((wnd->extension =
  337.                     malloc(strlen(FileName)+1)) != NULL)    {
  338.                 strcpy(wnd->extension, FileName);
  339.                 AddTitle(wnd, NameComponent(FileName));
  340.                 SendMessage(wnd, BORDER, 0, 0);
  341.             }
  342.         }
  343.         else
  344.             return;
  345.     }
  346.     if (wnd->extension != NULL)    {
  347.         WINDOW mwnd = MomentaryMessage("Saving the file");
  348.         if ((fp = fopen(wnd->extension, "wt")) != NULL)    {
  349.             fwrite(GetText(wnd), strlen(GetText(wnd)), 1, fp);
  350.             fclose(fp);
  351.             wnd->TextChanged = FALSE;
  352.         }
  353.         SendMessage(mwnd, CLOSE_WINDOW, 0, 0);
  354.     }
  355. }
  356. /* -------- delete a file ------------ */
  357. static void DeleteFile(WINDOW wnd)
  358. {
  359.     if (wnd->extension != NULL)    {
  360.         if (strcmp(wnd->extension, Untitled))    {
  361.             char *fn = NameComponent(wnd->extension);
  362.             if (fn != NULL)    {
  363.                 char msg[30];
  364.                 sprintf(msg, "Delete %s?", fn);
  365.                 if (YesNoBox(msg))    {
  366.                     unlink(wnd->extension);
  367.                     SendMessage(wnd, CLOSE_WINDOW, 0, 0);
  368.                 }
  369.             }
  370.         }
  371.     }
  372. }
  373. /* ------ display the row and column in the statusbar ------ */
  374. static void ShowPosition(WINDOW wnd)
  375. {
  376.     char status[30];
  377.     sprintf(status, "Line:%4d  Column: %2d",
  378.         wnd->CurrLine, wnd->CurrCol);
  379.     SendMessage(GetParent(wnd), ADDSTATUS, (PARAM) status, 0);
  380. }
  381. /* ----- window processing module for the editboxes ----- */
  382. static int EditorProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  383. {
  384.     int rtn;
  385.     switch (msg)    {
  386.         case SETFOCUS:
  387.             if ((int)p1)    {
  388.                 wnd->InsertMode = GetCommandToggle(&MainMenu, ID_INSERT);
  389.                 wnd->WordWrapMode = GetCommandToggle(&MainMenu, ID_WRAP);
  390.             }
  391.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  392.             if ((int)p1 == FALSE)
  393.                 SendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
  394.             else 
  395.                 ShowPosition(wnd);
  396.             return rtn;
  397.         case KEYBOARD_CURSOR:
  398.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  399.             ShowPosition(wnd);
  400.             return rtn;
  401.         case COMMAND:
  402.             switch ((int) p1)    {
  403.                 case ID_SEARCH:
  404.                     SearchText(wnd);
  405.                     return TRUE;
  406.                 case ID_REPLACE:
  407.                     ReplaceText(wnd);
  408.                     return TRUE;
  409.                 case ID_SEARCHNEXT:
  410.                     SearchNext(wnd);
  411.                     return TRUE;
  412.                 case ID_CUT:
  413.                     CopyToClipboard(wnd);
  414.                     SendMessage(wnd, COMMAND, ID_DELETETEXT, 0);
  415.                     SendMessage(wnd, PAINT, 0, 0);
  416.                     return TRUE;
  417.                 case ID_COPY:
  418.                     CopyToClipboard(wnd);
  419.                     ClearTextBlock(wnd);
  420.                     SendMessage(wnd, PAINT, 0, 0);
  421.                     return TRUE;
  422.                 case ID_PASTE:
  423.                     PasteFromClipboard(wnd);
  424.                     SendMessage(wnd, PAINT, 0, 0);
  425.                     return TRUE;
  426.                 case ID_HELP:
  427.                     DisplayHelp(wnd, "MEMOPADDOC");
  428.                     return TRUE;
  429.                 case ID_WRAP:
  430.                     wnd->WordWrapMode ^= TRUE;
  431.                     return TRUE;
  432.                 case ID_INSERT:
  433.                     wnd->InsertMode ^= TRUE;
  434.                     SendMessage(NULL, SHOW_CURSOR, wnd->InsertMode, 0);
  435.                     return TRUE;
  436.                 default:
  437.                     break;
  438.             }
  439.             break;
  440.         case CLOSE_WINDOW:
  441.             if (wnd->TextChanged)    {
  442.                 char *cp = malloc(25+strlen(GetTitle(wnd)));
  443.                 SendMessage(wnd, SETFOCUS, TRUE, 0);
  444.                 if (cp != NULL)    {
  445.                     strcpy(cp, GetTitle(wnd));
  446.                     strcat(cp, "\nText changed. Save it?");
  447.                     if (YesNoBox(cp))
  448.                         SendMessage(GetParent(wnd),
  449.                             COMMAND, ID_SAVE, 0);
  450.                     free(cp);
  451.                 }
  452.             }
  453.             wndpos = 0;
  454.             if (wnd->extension != NULL)    {
  455.                 free(wnd->extension);
  456.                 wnd->extension = NULL;
  457.             }
  458.             break;
  459.         default:
  460.             break;
  461.     }
  462.     return DefaultWndProc(wnd, msg, p1, p2);
  463. }
  464. /* -- point to the name component of a file specification -- */
  465. static char *NameComponent(char *FileName)
  466. {
  467.     char *Fname;
  468.     if ((Fname = strrchr(FileName, '\\')) == NULL)
  469.         if ((Fname = strrchr(FileName, ':')) == NULL)
  470.             Fname = FileName-1;
  471.     return Fname + 1;
  472. }
  473.  
  474. static char *ports[] = {
  475.     "Lpt1",    "Lpt2",    "Lpt3",
  476.     "Com1",    "Com2",    "Com3",    "Com4",
  477.       NULL
  478. };
  479.  
  480. static int PrintSetupProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  481. {
  482.     int rtn, i = 0, mar;
  483.     char marg[10];
  484.     WINDOW cwnd;
  485.     switch (msg)    {
  486.         case CREATE_WINDOW:
  487.             rtn = DefaultWndProc(wnd, msg, p1, p2);
  488.             PutItemText(wnd, ID_PRINTERPORT, cfg.PrinterPort);
  489.             while (ports[i] != NULL)
  490.                 PutComboListText(wnd, ID_PRINTERPORT, ports[i++]);
  491.             for (mar = CHARSLINE; mar >= 0; --mar)    {
  492.                 sprintf(marg, "%3d", mar);
  493.                 PutItemText(wnd, ID_LEFTMARGIN, marg);
  494.                 PutItemText(wnd, ID_RIGHTMARGIN, marg);
  495.             }
  496.             for (mar = LINESPAGE; mar >= 0; --mar)    {
  497.                 sprintf(marg, "%3d", mar);
  498.                 PutItemText(wnd, ID_TOPMARGIN, marg);
  499.                 PutItemText(wnd, ID_BOTTOMMARGIN, marg);
  500.             }
  501.             cwnd = ControlWindow(&PrintSetup, ID_LEFTMARGIN);
  502.             SendMessage(cwnd, LB_SETSELECTION,
  503.                 CHARSLINE-cfg.LeftMargin, 0);
  504.             cwnd = ControlWindow(&PrintSetup, ID_RIGHTMARGIN);
  505.             SendMessage(cwnd, LB_SETSELECTION,
  506.                 CHARSLINE-cfg.RightMargin, 0);
  507.             cwnd = ControlWindow(&PrintSetup, ID_TOPMARGIN);
  508.             SendMessage(cwnd, LB_SETSELECTION,
  509.                 LINESPAGE-cfg.TopMargin, 0);
  510.             cwnd = ControlWindow(&PrintSetup, ID_BOTTOMMARGIN);
  511.             SendMessage(cwnd, LB_SETSELECTION,
  512.                 LINESPAGE-cfg.BottomMargin, 0);
  513.             return rtn;
  514.         case COMMAND:
  515.             if ((int) p1 == ID_OK && (int) p2 == 0)    {
  516.                 GetItemText(wnd, ID_PRINTERPORT, cfg.PrinterPort, 4);
  517.                 cwnd = ControlWindow(&PrintSetup, ID_LEFTMARGIN);
  518.                 cfg.LeftMargin = CHARSLINE -
  519.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  520.                 cwnd = ControlWindow(&PrintSetup, ID_RIGHTMARGIN);
  521.                 cfg.RightMargin = CHARSLINE -
  522.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  523.                 cwnd = ControlWindow(&PrintSetup, ID_TOPMARGIN);
  524.                 cfg.TopMargin = LINESPAGE -
  525.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  526.                 cwnd = ControlWindow(&PrintSetup, ID_BOTTOMMARGIN);
  527.                 cfg.BottomMargin = LINESPAGE -
  528.                     SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
  529.             }
  530.             break;
  531.         default:
  532.             break;
  533.     }
  534.     return DefaultWndProc(wnd, msg, p1, p2);
  535. }
  536.  
  537. static void FixTabMenu(void)
  538. {
  539.     char *cp = GetCommandText(&MainMenu, ID_TABS);
  540.     if (cp != NULL)    {
  541.         cp = strchr(cp, '(');
  542.         if (cp != NULL)    {
  543.             *(cp+1) = cfg.Tabs + '0';
  544.             if (GetClass(inFocus) == POPDOWNMENU)
  545.                 SendMessage(inFocus, PAINT, 0, 0);
  546.         }
  547.     }
  548. }
  549.  
  550. void PrepFileMenu(void *w, struct Menu *mnu)
  551. {
  552.     WINDOW wnd = w;
  553.     DeactivateCommand(&MainMenu, ID_SAVE);
  554.     DeactivateCommand(&MainMenu, ID_SAVEAS);
  555.     DeactivateCommand(&MainMenu, ID_DELETEFILE);
  556.     DeactivateCommand(&MainMenu, ID_PRINT);
  557.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  558.         if (isMultiLine(wnd))    {
  559.             ActivateCommand(&MainMenu, ID_SAVE);
  560.             ActivateCommand(&MainMenu, ID_SAVEAS);
  561.             ActivateCommand(&MainMenu, ID_DELETEFILE);
  562.             ActivateCommand(&MainMenu, ID_PRINT);
  563.         }
  564.     }
  565. }
  566.  
  567. void PrepSearchMenu(void *w, struct Menu *mnu)
  568. {
  569.     WINDOW wnd = w;
  570.     DeactivateCommand(&MainMenu, ID_SEARCH);
  571.     DeactivateCommand(&MainMenu, ID_REPLACE);
  572.     DeactivateCommand(&MainMenu, ID_SEARCHNEXT);
  573.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  574.         if (isMultiLine(wnd))    {
  575.             ActivateCommand(&MainMenu, ID_SEARCH);
  576.             ActivateCommand(&MainMenu, ID_REPLACE);
  577.             ActivateCommand(&MainMenu, ID_SEARCHNEXT);
  578.         }
  579.     }
  580. }
  581.  
  582. void PrepEditMenu(void *w, struct Menu *mnu)
  583. {
  584.     WINDOW wnd = w;
  585.     DeactivateCommand(&MainMenu, ID_CUT);
  586.     DeactivateCommand(&MainMenu, ID_COPY);
  587.     DeactivateCommand(&MainMenu, ID_CLEAR);
  588.     DeactivateCommand(&MainMenu, ID_DELETETEXT);
  589.     DeactivateCommand(&MainMenu, ID_PARAGRAPH);
  590.     DeactivateCommand(&MainMenu, ID_PASTE);
  591.     DeactivateCommand(&MainMenu, ID_UNDO);
  592.     if (wnd != NULL && GetClass(wnd) == EDITBOX) {
  593.         if (isMultiLine(wnd))    {
  594.             if (TextBlockMarked(wnd))    {
  595.                 ActivateCommand(&MainMenu, ID_CUT);
  596.                 ActivateCommand(&MainMenu, ID_COPY);
  597.                 ActivateCommand(&MainMenu, ID_CLEAR);
  598.                 ActivateCommand(&MainMenu, ID_DELETETEXT);
  599.             }
  600.             ActivateCommand(&MainMenu, ID_PARAGRAPH);
  601.             if (!TestAttribute(wnd, READONLY) &&
  602.                         Clipboard != NULL)
  603.                 ActivateCommand(&MainMenu, ID_PASTE);
  604.             if (wnd->DeletedText != NULL)
  605.                 ActivateCommand(&MainMenu, ID_UNDO);
  606.         }
  607.     }
  608. }
  609.  
  610.